<template>
  <pro-dialog class="setdialog" ref="probjectModal" width="1200" :nopadding="true" :title="addAndExit ? '新增' : '编辑'">
    <div style="padding: 10px 20px">
      <YsForm ref="probjectFrom" :model="form" :rules="app_rule" label-position="top">
        <div class="form-title">检测工艺</div>
        <YsRow :gutter="10">
          <YsCol span="6">
            <YsFormItem label="检测工艺名称" prop="pd_name">
              <YsInput :maxlength="20" v-model="form.pd_name"></YsInput>
            </YsFormItem>
          </YsCol>
          <YsCol span="6">
            <YsFormItem label="检测工艺编号" prop="pd_code">
              <YsInput :maxlength="20" v-model="form.pd_code"></YsInput>
            </YsFormItem>
          </YsCol>
          <YsCol span="12">
            <YsFormItem label="备注" prop="remark">
              <YsInput v-model="form.remark" :class="curTheme" class="input-border" show-word-limit maxlength="30" placeholder="请输入"></YsInput>
            </YsFormItem>
          </YsCol>
        </YsRow>
        <div class="form-title">工艺参数</div>
        <YsRow :gutter="10">
          <YsCol span="4" v-for="(item, key, index) in inputItems" :key="index">
            <YsFormItem :label="item.label" :prop="key">
              <YsInput :maxlength="20" v-model="item.value"></YsInput>
            </YsFormItem>
          </YsCol>
        </YsRow>
      </YsForm>
      <YsRow class="foot-btn">
        <YsButton @click="handleCancel()">关闭</YsButton>
        <YsButton @click="handleOk('probjectFrom')" :loading="btnDisabled" type="primary">确定
        </YsButton>
      </YsRow>
    </div>
  </pro-dialog>
</template>

<script>
import { mapState, mapActions } from "vuex"
import setTime from '@/utils/setTime'
export default {
  name: "craftModal",
  computed: {
    ...mapState(['curTheme']),
  },
  props: {
    data: Object,
    addAndExit: Boolean
  },
  data() {
    return {
      btnDisabled: false,
      form: {
        jg: "",
        cllb: "",
        hd: "",
        remark: "",
      },
      app_rule: {
        pd_code: [
          { required: true, message: "检测工艺编号不能为空", trigger: "blur" },
        ],
        pd_name: [
          { required: true, message: "检测工艺名称不能为空", trigger: "blur" },
        ],
      },
      inputItems: {
        jg: {
          label: '适用范围中的结构',
          value: ''
        },
        cllb: {
          label: '适用范围中的材料类别',
          value: ''
        },
        hd: {
          label: '适用范围中的厚度',
          value: ''
        },
        zl: {
          label: '射线源种类',
          value: ''
        },
        nl: {
          label: '射线源能量',
          value: ''
        },
        jdc: {
          label: '射线源焦点尺',
          value: ''
        },
        jpxz: {
          label: '胶皮选择',
          value: ''
        },
        tzjs: {
          label: '透照技术',
          value: ''
        },
        cllb86: {
          label: '透照方式',
          value: ''
        },
        cllb99: {
          label: '胶片型号',
          value: ''
        },
        cllb88: {
          label: '胶片等级',
          value: ''
        },
        cllb77: {
          label: '像质计种类(类型)',
          value: ''
        },
        cllb66: {
          label: '增感屏(如使用)',
          value: ''
        },
        cllb55: {
          label: '滤光板型号(如使用)',
          value: ''
        },
        cllb44: {
          label: '胶片暗室处理方法或条件',
          value: ''
        },
        cllb33: {
          label: '底片观察技术',
          value: ''
        },
        cllb22: {
          label: '编制依据',
          value: ''
        },
        cllb00: {
          label: '尺寸范围',
          value: ''
        },
        c9llb: {
          label: '材料的种类',
          value: ''
        },
        c8llb: {
          label: '检测设备器材',
          value: ''
        },
        c7llb: {
          label: '射线源种类',
          value: ''
        },
        c6llb: {
          label: '射线源型号',
          value: ''
        },
        c5llb: {
          label: '射线源焦点尺寸',
          value: ''
        },
        c4llb: {
          label: '胶片牌号',
          value: ''
        },
        c2llb: {
          label: '胶片分类等级',
          value: ''
        },
        c1llb: {
          label: '增感屏类型',
          value: ''
        },
        c0llb: {
          label: '增感屏数量',
          value: ''
        },
        cllb: {
          label: '增感屏厚度',
          value: ''
        },
        cll9b: {
          label: '像质计型号',
          value: ''
        },
        cl8lb: {
          label: '滤光板',
          value: ''
        },
        cl7lb: {
          label: '背散射屏蔽铅板',
          value: ''
        },
        cl6lb: {
          label: '标记',
          value: ''
        },
        cl5lb: {
          label: '观察设备',
          value: ''
        },
        cll4b: {
          label: '检测技术等级',
          value: ''
        },
        cll3b: {
          label: '射线源',
          value: ''
        },
        cll2b: {
          label: '透照方向',
          value: ''
        },
        cll1b: {
          label: '胶片',
          value: ''
        },
        cllb12: {
          label: '曝光参数',
          value: ''
        },
        cllb11: {
          label: '像质计摆放位置',
          value: ''
        },
        cllb10: {
          label: '像质计数量',
          value: ''
        },
        cllb9: {
          label: '标记符号类型',
          value: ''
        },
        cllb8: {
          label: '标记符号放置情况',
          value: ''
        },
        cllb7: {
          label: '布片原则',
          value: ''
        },
        cllb6: {
          label: '底片质量要求',
          value: ''
        },
        cllb5: {
          label: '清晰度',
          value: ''
        },
        cllb4: {
          label: '黑度值',
          value: ''
        },
        cllb3: {
          label: '检测验收标准',
          value: ''
        },
        cllb0: {
          label: '操作指导书的验证要求',
          value: ''
        },
        cllb2: {
          label: '检测区',
          value: ''
        },
        cllb1: {
          label: '焊接头表面要求',
          value: ''
        },
      }
    }
  },
  methods: {
    ...mapActions(['addSpringProjectAPI', 'editSpringProjectAPI']),
    //确认
    handleOk(name) {
      this.$refs[name].validate((valid) => {
        if (valid) {
          if (this.addAndExit) {
            this.addProbjectItem()
          } else {
            this.exitProbjectItem()
          }
        }
      })
    },
    //取消
    handleCancel() {
      this.$refs.probjectModal.close()
    },
    //新增
    addProbjectItem() {
      let _this = this
      this.btnDisabled = true
      if (typeof _this.form.production_date === "object") {
        _this.form.production_date = setTime.getNowFormatDate(_this.form.production_date)
      }
      _this.addSpringProjectAPI({ form: _this.form }).then((res) => {
        let { msg, status } = res
        this.btnDisabled = false
        if (status === "ok") {
          _this.$YsMessage.success("新增成功")
          _this.$emit("handleRefresh")
          _this.$refs.probjectModal.close()
        } else {
          _this.$YsMessage.error(msg)
        }
      }).catch((err) => {
        _this.$YsMessage.error(err)
      })
    },
    //编辑
    exitProbjectItem() {
      let _this = this
      this.btnDisabled = true
      if (typeof _this.form.production_date === "object") {
        _this.form.production_date = setTime.getNowFormatDate(_this.form.production_date)
      }
      _this.editSpringProjectAPI({ form: _this.form }).then((res) => {
        let { data, msg, scode, status } = res
        this.btnDisabled = false
        if (status === "ok") {
          _this.$YsMessage.success("编辑成功")
          _this.$emit("handleRefresh")
          _this.$refs.probjectModal.close()
        } else {
          _this.$YsMessage.error(msg)
        }
      }).catch((err) => {
        _this.$YsMessage.error(err)
      })
    },
    // 打开窗口
    open() {
      this.$refs.probjectFrom.resetFields()
      this.$refs.probjectModal.show()
    }
  },
  watch: {
    data(nv) {
      this.form = Object.assign(this.form, nv)
      Object.keys(this.inputItems)?.forEach((item) => {
        this.inputItems[item].value = this.form[item]
      })
    }
  }
}
</script>

<style lang="less" scoped>
.form-title {
  margin-top: 10px;
  margin-bottom: 10px;
  &:nth-child(1){
    margin-top: 0px;
  }
}
/deep/ .ivu-form-item {
  margin-bottom: 12px !important;
}

/deep/ .ivu-form-item-label {
  font-size: 14px !important;
}
</style>